package com.supermarket.manage.provider.ucenter.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.supermarket.manage.common.pojo.Buyer;
import com.supermarket.manage.provider.api.ucenter.BuyerService;
import com.supermarket.manage.provider.ucenter.mapper.BuyerMapper;
import org.apache.dubbo.config.annotation.Service;

import javax.annotation.Resource;

/**
 * @author Faxon
 * @version 1.0
 * @date 2020-02-26 17:04
 **/
@Service(version = "1.0.0", timeout = 5000)
public class BuyerServiceImpl implements BuyerService {

    @Resource
    private BuyerMapper buyerMapper;

    @Override
    public Integer getCountByName(String name) {
        QueryWrapper<Buyer> wrapper = new QueryWrapper<>();
        wrapper.eq("name", name);
        return buyerMapper.selectCount(wrapper);
    }

    @Override
    public Integer getCountByPhone(String phone) {
        QueryWrapper<Buyer> wrapper = new QueryWrapper<>();
        wrapper.eq("phone", phone);
        return buyerMapper.selectCount(wrapper);
    }

    @Override
    public String insertBuyer(Buyer buyer) {
        int insert = buyerMapper.insert(buyer);
        if (insert == 1) {
            return buyer.getId();
        }
        return null;
    }

    @Override
    public int getCountByShopName(String shopName) {
        QueryWrapper<Buyer> wrapper = new QueryWrapper<>();
        wrapper.eq("shop_name", shopName);
        return buyerMapper.selectCount(wrapper);
    }

    @Override
    public String getMarketNameByBuyerId(String buyerId) {
        QueryWrapper<Buyer> wrapper = new QueryWrapper<>();
        wrapper.eq("id", buyerId).select("shop_name");
        Buyer buyer = buyerMapper.selectOne(wrapper);
        return buyer.getShopName();
    }

}
